// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.


suite("test_cast_to_largeint_from_decimal128i_38_19") {

    // This test case is generated from the correspoinding be UT test case,
    // update this case if the correspoinding be UT test case is updated,
    // e.g.: ../run-be-ut.sh --run --filter=FunctionCastToDecimalTest.* --gen_regression_case
    sql "drop table if exists test_cast_to_largeint_from_decimal128i_38_19_0_nullable;"
    sql "create table test_cast_to_largeint_from_decimal128i_38_19_0_nullable(f1 int, f2 decimalv3(38, 19)) properties('replication_num'='1');"
    sql """insert into test_cast_to_largeint_from_decimal128i_38_19_0_nullable values (0, "0.0000000000000000000"),(1, "0.0000000000000000000"),(2, "0.0000000000000000001"),(3, "-0.0000000000000000001"),(4, "0.0000000000000000009"),(5, "-0.0000000000000000009"),(6, "0.9999999999999999999"),(7, "-0.9999999999999999999"),(8, "0.9999999999999999998"),(9, "-0.9999999999999999998"),(10, "0.0999999999999999999"),(11, "-0.0999999999999999999"),(12, "0.9000000000000000000"),(13, "-0.9000000000000000000"),(14, "0.9000000000000000001"),(15, "-0.9000000000000000001"),(16, "1.0000000000000000000"),(17, "-1.0000000000000000000"),(18, "1.0000000000000000001"),(19, "-1.0000000000000000001"),
      (20, "1.0000000000000000009"),(21, "-1.0000000000000000009"),(22, "1.9999999999999999999"),(23, "-1.9999999999999999999"),(24, "1.9999999999999999998"),(25, "-1.9999999999999999998"),(26, "1.0999999999999999999"),(27, "-1.0999999999999999999"),(28, "1.9000000000000000000"),(29, "-1.9000000000000000000"),(30, "1.9000000000000000001"),(31, "-1.9000000000000000001"),(32, "9.0000000000000000000"),(33, "-9.0000000000000000000"),(34, "9.0000000000000000001"),(35, "-9.0000000000000000001"),(36, "9.0000000000000000009"),(37, "-9.0000000000000000009"),(38, "9.9999999999999999999"),(39, "-9.9999999999999999999"),
      (40, "9.9999999999999999998"),(41, "-9.9999999999999999998"),(42, "9.0999999999999999999"),(43, "-9.0999999999999999999"),(44, "9.9000000000000000000"),(45, "-9.9000000000000000000"),(46, "9.9000000000000000001"),(47, "-9.9000000000000000001"),(48, "9999999999999999999.0000000000000000000"),(49, "-9999999999999999999.0000000000000000000"),(50, "9999999999999999999.0000000000000000001"),(51, "-9999999999999999999.0000000000000000001"),(52, "9999999999999999999.0000000000000000009"),(53, "-9999999999999999999.0000000000000000009"),(54, "9999999999999999999.9999999999999999999"),(55, "-9999999999999999999.9999999999999999999"),(56, "9999999999999999999.9999999999999999998"),(57, "-9999999999999999999.9999999999999999998"),(58, "9999999999999999999.0999999999999999999"),(59, "-9999999999999999999.0999999999999999999"),
      (60, "9999999999999999999.9000000000000000000"),(61, "-9999999999999999999.9000000000000000000"),(62, "9999999999999999999.9000000000000000001"),(63, "-9999999999999999999.9000000000000000001"),(64, "9999999999999999998.0000000000000000000"),(65, "-9999999999999999998.0000000000000000000"),(66, "9999999999999999998.0000000000000000001"),(67, "-9999999999999999998.0000000000000000001"),(68, "9999999999999999998.0000000000000000009"),(69, "-9999999999999999998.0000000000000000009"),(70, "9999999999999999998.9999999999999999999"),(71, "-9999999999999999998.9999999999999999999"),(72, "9999999999999999998.9999999999999999998"),(73, "-9999999999999999998.9999999999999999998"),(74, "9999999999999999998.0999999999999999999"),(75, "-9999999999999999998.0999999999999999999"),(76, "9999999999999999998.9000000000000000000"),(77, "-9999999999999999998.9000000000000000000"),(78, "9999999999999999998.9000000000000000001"),(79, "-9999999999999999998.9000000000000000001"),
      (80, "999999999999999999.0000000000000000000"),(81, "-999999999999999999.0000000000000000000"),(82, "999999999999999999.0000000000000000001"),(83, "-999999999999999999.0000000000000000001"),(84, "999999999999999999.0000000000000000009"),(85, "-999999999999999999.0000000000000000009"),(86, "999999999999999999.9999999999999999999"),(87, "-999999999999999999.9999999999999999999"),(88, "999999999999999999.9999999999999999998"),(89, "-999999999999999999.9999999999999999998"),(90, "999999999999999999.0999999999999999999"),(91, "-999999999999999999.0999999999999999999"),(92, "999999999999999999.9000000000000000000"),(93, "-999999999999999999.9000000000000000000"),(94, "999999999999999999.9000000000000000001"),(95, "-999999999999999999.9000000000000000001"),(96, "9000000000000000000.0000000000000000000"),(97, "-9000000000000000000.0000000000000000000"),(98, "9000000000000000000.0000000000000000001"),(99, "-9000000000000000000.0000000000000000001"),
      (100, "9000000000000000000.0000000000000000009"),(101, "-9000000000000000000.0000000000000000009"),(102, "9000000000000000000.9999999999999999999"),(103, "-9000000000000000000.9999999999999999999"),(104, "9000000000000000000.9999999999999999998"),(105, "-9000000000000000000.9999999999999999998"),(106, "9000000000000000000.0999999999999999999"),(107, "-9000000000000000000.0999999999999999999"),(108, "9000000000000000000.9000000000000000000"),(109, "-9000000000000000000.9000000000000000000"),(110, "9000000000000000000.9000000000000000001"),(111, "-9000000000000000000.9000000000000000001"),(112, "9000000000000000001.0000000000000000000"),(113, "-9000000000000000001.0000000000000000000"),(114, "9000000000000000001.0000000000000000001"),(115, "-9000000000000000001.0000000000000000001"),(116, "9000000000000000001.0000000000000000009"),(117, "-9000000000000000001.0000000000000000009"),(118, "9000000000000000001.9999999999999999999"),(119, "-9000000000000000001.9999999999999999999"),
      (120, "9000000000000000001.9999999999999999998"),(121, "-9000000000000000001.9999999999999999998"),(122, "9000000000000000001.0999999999999999999"),(123, "-9000000000000000001.0999999999999999999"),(124, "9000000000000000001.9000000000000000000"),(125, "-9000000000000000001.9000000000000000000"),(126, "9000000000000000001.9000000000000000001"),(127, "-9000000000000000001.9000000000000000001")
      ,(128, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_0_strict 'select f1, cast(f2 as largeint) from test_cast_to_largeint_from_decimal128i_38_19_0_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_0_non_strict 'select f1, cast(f2 as largeint) from test_cast_to_largeint_from_decimal128i_38_19_0_nullable order by 1;'

    sql "drop table if exists test_cast_to_largeint_from_decimal128i_38_19_0_not_nullable;"
    sql "create table test_cast_to_largeint_from_decimal128i_38_19_0_not_nullable(f1 int, f2 decimalv3(38, 19)) properties('replication_num'='1');"
    sql """insert into test_cast_to_largeint_from_decimal128i_38_19_0_not_nullable values (0, "0.0000000000000000000"),(1, "0.0000000000000000000"),(2, "0.0000000000000000001"),(3, "-0.0000000000000000001"),(4, "0.0000000000000000009"),(5, "-0.0000000000000000009"),(6, "0.9999999999999999999"),(7, "-0.9999999999999999999"),(8, "0.9999999999999999998"),(9, "-0.9999999999999999998"),(10, "0.0999999999999999999"),(11, "-0.0999999999999999999"),(12, "0.9000000000000000000"),(13, "-0.9000000000000000000"),(14, "0.9000000000000000001"),(15, "-0.9000000000000000001"),(16, "1.0000000000000000000"),(17, "-1.0000000000000000000"),(18, "1.0000000000000000001"),(19, "-1.0000000000000000001"),
      (20, "1.0000000000000000009"),(21, "-1.0000000000000000009"),(22, "1.9999999999999999999"),(23, "-1.9999999999999999999"),(24, "1.9999999999999999998"),(25, "-1.9999999999999999998"),(26, "1.0999999999999999999"),(27, "-1.0999999999999999999"),(28, "1.9000000000000000000"),(29, "-1.9000000000000000000"),(30, "1.9000000000000000001"),(31, "-1.9000000000000000001"),(32, "9.0000000000000000000"),(33, "-9.0000000000000000000"),(34, "9.0000000000000000001"),(35, "-9.0000000000000000001"),(36, "9.0000000000000000009"),(37, "-9.0000000000000000009"),(38, "9.9999999999999999999"),(39, "-9.9999999999999999999"),
      (40, "9.9999999999999999998"),(41, "-9.9999999999999999998"),(42, "9.0999999999999999999"),(43, "-9.0999999999999999999"),(44, "9.9000000000000000000"),(45, "-9.9000000000000000000"),(46, "9.9000000000000000001"),(47, "-9.9000000000000000001"),(48, "9999999999999999999.0000000000000000000"),(49, "-9999999999999999999.0000000000000000000"),(50, "9999999999999999999.0000000000000000001"),(51, "-9999999999999999999.0000000000000000001"),(52, "9999999999999999999.0000000000000000009"),(53, "-9999999999999999999.0000000000000000009"),(54, "9999999999999999999.9999999999999999999"),(55, "-9999999999999999999.9999999999999999999"),(56, "9999999999999999999.9999999999999999998"),(57, "-9999999999999999999.9999999999999999998"),(58, "9999999999999999999.0999999999999999999"),(59, "-9999999999999999999.0999999999999999999"),
      (60, "9999999999999999999.9000000000000000000"),(61, "-9999999999999999999.9000000000000000000"),(62, "9999999999999999999.9000000000000000001"),(63, "-9999999999999999999.9000000000000000001"),(64, "9999999999999999998.0000000000000000000"),(65, "-9999999999999999998.0000000000000000000"),(66, "9999999999999999998.0000000000000000001"),(67, "-9999999999999999998.0000000000000000001"),(68, "9999999999999999998.0000000000000000009"),(69, "-9999999999999999998.0000000000000000009"),(70, "9999999999999999998.9999999999999999999"),(71, "-9999999999999999998.9999999999999999999"),(72, "9999999999999999998.9999999999999999998"),(73, "-9999999999999999998.9999999999999999998"),(74, "9999999999999999998.0999999999999999999"),(75, "-9999999999999999998.0999999999999999999"),(76, "9999999999999999998.9000000000000000000"),(77, "-9999999999999999998.9000000000000000000"),(78, "9999999999999999998.9000000000000000001"),(79, "-9999999999999999998.9000000000000000001"),
      (80, "999999999999999999.0000000000000000000"),(81, "-999999999999999999.0000000000000000000"),(82, "999999999999999999.0000000000000000001"),(83, "-999999999999999999.0000000000000000001"),(84, "999999999999999999.0000000000000000009"),(85, "-999999999999999999.0000000000000000009"),(86, "999999999999999999.9999999999999999999"),(87, "-999999999999999999.9999999999999999999"),(88, "999999999999999999.9999999999999999998"),(89, "-999999999999999999.9999999999999999998"),(90, "999999999999999999.0999999999999999999"),(91, "-999999999999999999.0999999999999999999"),(92, "999999999999999999.9000000000000000000"),(93, "-999999999999999999.9000000000000000000"),(94, "999999999999999999.9000000000000000001"),(95, "-999999999999999999.9000000000000000001"),(96, "9000000000000000000.0000000000000000000"),(97, "-9000000000000000000.0000000000000000000"),(98, "9000000000000000000.0000000000000000001"),(99, "-9000000000000000000.0000000000000000001"),
      (100, "9000000000000000000.0000000000000000009"),(101, "-9000000000000000000.0000000000000000009"),(102, "9000000000000000000.9999999999999999999"),(103, "-9000000000000000000.9999999999999999999"),(104, "9000000000000000000.9999999999999999998"),(105, "-9000000000000000000.9999999999999999998"),(106, "9000000000000000000.0999999999999999999"),(107, "-9000000000000000000.0999999999999999999"),(108, "9000000000000000000.9000000000000000000"),(109, "-9000000000000000000.9000000000000000000"),(110, "9000000000000000000.9000000000000000001"),(111, "-9000000000000000000.9000000000000000001"),(112, "9000000000000000001.0000000000000000000"),(113, "-9000000000000000001.0000000000000000000"),(114, "9000000000000000001.0000000000000000001"),(115, "-9000000000000000001.0000000000000000001"),(116, "9000000000000000001.0000000000000000009"),(117, "-9000000000000000001.0000000000000000009"),(118, "9000000000000000001.9999999999999999999"),(119, "-9000000000000000001.9999999999999999999"),
      (120, "9000000000000000001.9999999999999999998"),(121, "-9000000000000000001.9999999999999999998"),(122, "9000000000000000001.0999999999999999999"),(123, "-9000000000000000001.0999999999999999999"),(124, "9000000000000000001.9000000000000000000"),(125, "-9000000000000000001.9000000000000000000"),(126, "9000000000000000001.9000000000000000001"),(127, "-9000000000000000001.9000000000000000001");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_0_strict 'select f1, cast(f2 as largeint) from test_cast_to_largeint_from_decimal128i_38_19_0_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_0_non_strict 'select f1, cast(f2 as largeint) from test_cast_to_largeint_from_decimal128i_38_19_0_not_nullable order by 1;'

}